/**
 * jims
 */
package com.jims.master.modules.med.service;

import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.CrudService;
import com.jims.master.common.web.impl.BaseDto;
import com.jims.master.modules.doctor.dao.ClinicOrdersDao;
import com.jims.master.modules.med.dao.HisVsMedicalDao;
import com.jims.master.modules.med.dao.OrgVsProvinceDao;
import com.jims.master.modules.med.entity.HisVsMedical;
import com.jims.master.modules.oper.dao.PriceListDao;
import com.jims.master.modules.oper.entity.PriceList;
import com.jims.master.modules.sys.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * 医保数据与his数据对照Service
 * @author 陈晓阳
 * @version 2017-06-06
 */
@Service
@Transactional(readOnly = true)
public class HisVsMedicalService extends CrudService<HisVsMedicalDao, HisVsMedical> {

    @Autowired
    private PriceListDao priceListDao;
    @Autowired
    private OrgVsProvinceDao orgVsProvinceDao;
    @Autowired
    private HisVsMedicalDao hisVsMedicalDao;
    @Autowired
    private ClinicOrdersDao clinicOrdersDao;


	public HisVsMedical get(String id) {
		return super.get(id);
	}
	
	public List<HisVsMedical> findList(HisVsMedical hisVsMedical) {
		return super.findList(hisVsMedical);
	}
	
	public Page<HisVsMedical> findPage(Page<HisVsMedical> page, HisVsMedical hisVsMedical) {
		return super.findPage(page, hisVsMedical);
	}
	
	@Transactional(readOnly = false)
	public int save(HisVsMedical hisVsMedical) {
        int resultVal = super.save(hisVsMedical);
        return resultVal;
    }
    /**
     * 根据价表Id获取价表信息
     * @return
     */
    @Transactional(readOnly = true)
    public HisVsMedical findByPriceId(String priceId) {
        HisVsMedical hisVsMedical = hisVsMedicalDao.findByPriceId(priceId);
        return hisVsMedical;
    }
    /**
     * 医保项目添加对照，查询医保数据
     * @return
     */
    public List<HisVsMedical> findListByParam(String q, String limit) {
        return hisVsMedicalDao.findListByParam(q, limit);
    }
    /**
     * 根据hisVsMedical-id 获取
     * @return
     */
    @Transactional(readOnly = true)
    public HisVsMedical getById(String id) {
        HisVsMedical hisVsMedical = hisVsMedicalDao.get(id);
        return hisVsMedical;
    }
	@Transactional(readOnly = false)
	public int delete(HisVsMedical hisVsMedical) {
		return super.delete(hisVsMedical);
	}




    //---------------------------------------------------

    /**
     * 根据页面传来的代收费Id转换成为 对照之后医保数据
     * 1 只有通过医保卡挂号的病人才可以进行医保报销---上传数据之后 将代收费信息挂起--用到patiengId
     * @param clinicOrdersId  代收费表主键
     * @return
     */
    public List<HisVsMedical> hisVsMedicalList(String clinicOrdersId){
        String provinceLabel=orgVsProvinceDao.getProvince(UserUtils.getOrgId());
        String[] arry=clinicOrdersId.split(",");
        List<HisVsMedical> list=hisVsMedicalDao.findByPrice(provinceLabel,Arrays.asList(arry));
        return list;
    }

    /**
     *
     * @param ordersIds
     * @param provinceLabel
     * @return
     */
    public List<BaseDto> queryByOrders(List<String> ordersIds, String provinceLabel) {
//        return hisVsMedicalDao.queryByOrders(ordersIds,provinceLabel);
        //1 查询项目类别
//        List<ConfirmTable> confirmTables=clinicOrdersDao.findItemClass(ordersIds);
        //2 根据项目类别 确定表名
        // 确定价表Id集合

        //3 根据表名    确定sql
        //4 执行sql 返回查询结果
        return null;
    }

}